<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String basepath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ request.getContextPath() + "/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<link rel="stylesheet" href="css/admin_add.css" />
<div class="body_top">
	<div>
		<p>管理投资人</p>
		<div>
			<p>INTRODUUCTION OF INVESTORS</p>
			<p class="last_p">PUSH YOUR BACK REDUCE YOUR TIME</p>
		</div>
	</div>
</div>
<div id="teac_all">
<form action="admin/addInve" method="post">
<div class="add_teacbox clearfix" >
	<div>
		<p><b>*单位</b><input type="text" name="name"><span></span></p>
		<p><b>*邮箱</b><input type="email" name="loname"><span></span></p>
		<p><b>*电话</b><input type="text" name="tel"><span></span></p>
		<p><b>*地址</b><input type="text" name="addr"><span></span></p>
	</div>
	<div><textarea placeholder="请输入公司简介" name="explain"></textarea></div>
	<div>
		<input type="submit" value="添加">
		<input id="cancel_teac" type="reset" value="取消" > 			
	</div>
</div>
</form>
<div class="ds clearfix yjtzr">
    <div id="div_detail">
        <span id="close_div"></span>
        <div id="detail_content">
        <p>ID:</p><p>姓名：</p><p>邮箱：</p><p>电话：</p><p>登录名：</p><p>公司简介：</p>
        </div>
    </div>
	<div class="tjds">
		<img src="img/tjds.png"><span>添加投资人</span>
	</div>
	<div id="each_teac">
		<c:forEach items="${requestScope.investors }" var="investor">
			<div>
				<div class="ds_left">
					<img
						src="${investor.i_logo != null ? investor.i_logo : 'img/tutor2.png'}">
				</div>
				<div class="ds_right">
				<span class="remove">一</span>
					<p>
						<b>ID：</b><span>${investor.i_id }</span>
					</p>
					<p>
						<b>姓名：</b><span>${investor.i_name }</span>
					</p>
					<p>
						<b>简介：</b><span>${investor.i_explain }</span>
					</p>
				</div>
				<div class="ds_bottom">
					<button>查看更多</button>
				</div>
			</div>
		</c:forEach>
	</div>
	
</div>
</div>
<div class="fy" title="${sum != null?sum:1 }">
			<span id="pre_page">上一页</span>
			<ul>
			</ul>
			<span id="next_page">下一页</span>
		</div>

<script type="text/javascript">
$(document).ready(function(){
	//类型选择
	var kind="inve";
	var type="";
	/*  var sum =$("div.fy").attr("title"); */
	var sum = 20;
	var connect_page=0;
	printList(1);
	//添加投资人信息的弹出框
	$(".tjds").click(function(){
			$("div.add_teacbox").slideToggle();
		});
	$("#cancel_teac").click(function(){
		$("div.add_teacbox").slideUp();
	})

	
	//删除数据投资人
	
		$("#each_teac").delegate('.remove','click',function(){
			if(confirm("确定删除?")){
				//取得被删投资人的id值
				var tea_id = $(this).next().children('span').text();
				var that= $(this);
				//返回数据
				var obj_id={
                    type:"inve",
					id:tea_id	
				};
                console.log(obj_id);
				 getData("admin/del",delete_teac,obj_id,that); 
				
			}
		})
		
		//删除投资人页面响应
		function delete_teac(data,that){
		if(data){
			that.parent().parent().css("display","none");
		}else{
			alert("删除失败，请重试！");
		}
	}
		//查看投资人详细信息
		$("#each_teac").delegate('button','click',function(){
            var teac_id =$(this).parent().prev().children().eq(1).children('span').text();
            var that =$(this);
            var address="admin/seekInfo?type=inve&&id="+teac_id;
            console.log(address);
             getData(address,see_inve); 
        })

        //投资人详情的回调函数 
        function see_inve(data){
            $("#div_detail").slideDown(400);
            $(".back_shadow").css("display","block");
            var inve=data.inve;
            console.log(inve);
            $("#detail_content").html("<p><b>ID：</b>"+inve.i_id+"</p><p><b>单位：</b>"+0+"</p><p><b>姓名：</b>"+inve.i_name+"</p><p><b>邮箱：</b>"+inve.i_loname+"</p><p><b>电话：</b>"+0+"</p><p><b>登录名：</b>"+inve.i_loname+"</p><p><b>地址：</b>"+0+"</p><p><b>注册时间：</b>"+inve.i_ctime+"</p><p><b>公司简介：</b>"+inve.i_explain+"</p>")
            
        }
//         {
//             "inve": {
//         "i_passw": "F59BD65F7EDAFB087A81D4DCA06C4910",
//         "i_id": 1,
//         "i_explain": "我是投资人哦！别来惹我",
//         "i_amount": 0,
//         "i_ctime": "2015-11-23",
//         "i_name": "南方电网",
//         "i_loname": "touzi"
//     }
//     "invePro": [
//         {
//             "list": [
//                 {
//                     "p_name": "高大上的项目",
//                     "p_content": "我们的项目就是全宇宙最高大上的。",
//                     "pt_id": 1,
//                     "p_view": 1,
//                     "p_explain": "就是NB",
//                     "p_status": 2,
//                     "p_ctime": "2015-11-23",
//                     "p_progress": 0,
//                     "p_id": 1,
//                     "te_id": 1
//                 },
//                 {
//                     "pt_id": 1,
//                     "pt_name": "qita",
//                     "pt_explain": ""
//                 },
//                 {
//                     "pi_amount": 25552,
//                     "i_id": 1,
//                     "pi_time": "2015-11-23",
//                     "pi_explain": "我很看中这个项目！有潜力。",
//                     "p_id": 1,
//                     "pi_id": 1
//                 }
//             ]
//         }
//     ],
    
// }

        $("#close_div,.back_shadow").click(function(){
            $("#div_detail").slideUp(400);
            $(".back_shadow").css("display","none");
        })


// 分页及动态写数据	  admin/fenye?html=teac&&type=?&&page=?

	 
   function printList(index){
     var fy_html="";
     var show = sum-index>7?8:sum-index+1;
     if(index<=connect_page){
         for(var i=8;i>0;i--){
             fy_html+="<li>"+(index-i+1)+"</li>";
         }
         $(".fy>ul").html(fy_html);
         $(".fy>ul>li").eq(7).addClass('fy_on');
     }else{
         for(var i=0;i<show;i++){
             fy_html+="<li>"+(index+i)+"</li>";
         }
         $(".fy>ul").html(fy_html);
         $(".fy>ul>li").eq(0).addClass('fy_on');
     }
     connect_page=index;
 }
	    //点击分页  分别触发ajax事件以及分页列表事件
	    $(".fy>ul").delegate('li','click',function(){
	        type=$("#bg_black").attr("title");
	        $(this).addClass('fy_on');
	        $(this).siblings("li").attr("class","");
	        var page = $(this).html();
	        if(sum>8&&(page%7==1)&&page>7){
	            printList(Number(page));
	            }else{
	                connect_page=page;
	            }
	            connect_data(kind,page,type);
	            
	        })
	$("#pre_page").click(function(){
     var pre_page=(connect_page-1)%7;
     pre_page= pre_page==0?7:pre_page;
     $("div.fy>ul>li").eq(pre_page-1).trigger("click");
 });
 
  $("#next_page").click(function(){
     var next_page=(Number(connect_page)+1)%7;
      next_page= next_page==0?7:next_page ;
      next_page= next_page==1?8:next_page ;
     $("div.fy>ul>li").eq(next_page-1).trigger("click");
 }) 
 
	
 // 上一页  and 下一页

 function connect_data(kind,page,type){
     type= (type == undefined?"":"&&type="+type);
     var address ="admin/fenye?html="+kind+type+"&&page="+page;
     getData(address,printNews)
     console.log(address);
 }
 // ajax传值取相应数据
 function getData(address,callback,Data,that){
     $.ajax({
         type:"post",
         url:address,
         data:Data,
         dataType:"json",
         success:function(data){
        	 console.log(data);
             callback(data,that);
         },
         error:function(e){
             console.log(e.message);
         }
     });
 }
	        
	//回调函数渲染页面
	function printNews(data){
		var teac_html="";
		$.each(data.paging,function(){
			teac_html+= "<div class='ds'><div class='ds_left'><img src='img/tutor1.png'/></div><div class='ds_right'><span class='remove'>一</span><p>ID:<span>"+this.i_id+"</span></p><p>姓名:"+this.i_name+"</p><p>邮箱:"+this.i_loname+"</p><p>电话:"+this.tu_tel+"</p></p></div><div class='ds_bottom'><button>查看更多</button></div></div>";
		});
		$("#each_teac").html(teac_html);
	}

    $(".add_teacbox>div>p>input").blur(function(){
        var input_name= $(this).attr("name");
        var input_data=$(this).val();
        var input_html;
        var judge;
        if(!input_data){
            input_html=" 必填字段!"
        }else{
        switch (input_name){
            case 'zhizhao':
                judge=/^\d{5}$/
              break;
            case 'charger':
                judge=/^([\u4e00-\u9fa5]+|([a-zA-Z]+\s?)+)$/;
                break;
            case 'danwei':
                judge=/^([\u4e00-\u9fa5]+|([a-zA-Z]+\s?)+)$/;
                break;
            case 'email':
                judge=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
                break;
            
            case 'phone':
                judge=/^([0-9]{11})?$/;
                break;
             case 'address':
                 judge=/^[\u4e00-\u9fa5]+$/;
                break;
            default:
            }
            if(!judge.test(input_data)){
                input_html=" 录入有误!";
            }else{
                input_html="";
            }
        }
        $(this).next().html(input_html);
 })
})
</script>